package com.maxqaq.controller;

import com.maxqaq.constant.MessageConstant;
import com.maxqaq.result.Result;
import com.maxqaq.service.ReportService;
import com.maxqaq.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//import org.springframework.security.access.prepost.PreAuthorize;


@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    //@PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/vip")
    public Result vip(String type) {
        if (type == null) {
            return new Result(false, MessageConstant.REPORT_VIP_TYPE_EMPTY);
        }
        //半年前数据
        if (MessageConstant.HALF_YEAR_AGO.equals(type)) {
            return reportService.vip(DateUtil.getHalfYearAgo(), DateUtil.getNowDate());
        }
        //一年前数据
        if (MessageConstant.ONE_YEAR_AGO.equals(type)) {
            return reportService.vip(DateUtil.getOneYearAgo(), DateUtil.getNowDate());
        }
        //三年前的数据
        if (MessageConstant.THREE_YEAR_AGO.equals(type)) {
            return reportService.vip(DateUtil.getThreeYearAgo(), DateUtil.getNowDate());
        }
        return null;
    }
}
